# -*- coding:utf-8 -*-
# @time    : 2021/9/5 8:17
# @Author  : zhang jin xia
# @Filename: PyCharm
import logging

from appium.webdriver.webdriver import WebDriver

# 初始化一个logger
logger=logging.getLogger()
class BasePage:
    # 初始化driver，初始值为None
    def __init__(self, driver: WebDriver=None):
        self.driver= driver

    # 封装find_element方法, *解包
    # def find(self,by,locator=None):
    #     if locator is None:
    #         return self.find(*by)
    #     else:
    #         return self.driver.find_element(by=by,value=locator)
    def find(self,by,value):
        logger.info("find")
        logger.info(by)
        logger.info(value)
        return self.driver.find_element(by,value)

    # 封装find_element().click()方法
    def find_and_click(self,by,value):
        logger.info("find_and_click")
        logger.info(by)
        logger.info(value)
        return self.find(by,value).click()

    # 封装find_element.send_keys()方法
    def find_and_send(self,by,value,text):
        logger.info("find_and_send")
        logger.info(by)
        logger.info(value)
        logger.info(text)
        return self.find(by,value).send_keys(text)

    # 滚动查找元素，并点击
    def scroll_find_and_click(self,by):
        logger.info("scroll_find_and_click")
        logger.info(text)
        return self.driver.find_element_by_android_uiautomator(by).click()

    # 封装返回操作
    def back(self,num=3):
        logger.info("back")
        for i in range(0,num):
            self.driver.back()


